package leetcode_题库;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Ding
 * @create 2022/8/16 19:18
 */
public class _704_二分查找 {
    public static void main(String[] args) {
        int[] num = new int[]{-1,0,3,5,9,12};

        int target = 9;

        System.err.println(getMid(num, target));
    }

    public static int getMid(int[] num, int target) {
        int lp = 0;
        int rp = num.length - 1;
        while (lp <= rp) {
            int m = lp + (rp - lp) / 2;
            if (num[m] > target) {
                rp = m - 1;
            } else if (num[m] < target){
                lp = m + 1;
            }else{
                return m;
            }
        }
        return -1;
    }
}
